package com.xexun.gpstracker.my.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xexun.gpstracker.channel.R;
import com.xexun.gpstracker.util.CommUtil;
import com.xexun.gpstracker.vo.StepCounter;

public class StepAdapter extends BaseAdapter {
    private Context context;
    private List<StepCounter> list;
    private String termImei;

    public StepAdapter(Context context, List<StepCounter> list, String termImei) {
        this.context = context;
        this.list = list;
        this.termImei = termImei;
    }

    static class ContViewHolder {
        TextView date, step;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public StepCounter getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return list.get(position).getStepId();
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final ContViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.activity_step_list_item, null);
            holder = new ContViewHolder();
            convertView.setTag(holder);
            holder.date = (TextView) convertView.findViewById(R.id.step_date);
            holder.step = (TextView) convertView.findViewById(R.id.step_count);
        } else {
            holder = (ContViewHolder) convertView.getTag();
        }
        final StepCounter step = list.get(position);
        holder.date.setText(CommUtil.getDate(step.getDate()));
        holder.step.setText(CommUtil.toStr(step.getStep()) + " " + context.getString(R.string.step));
        return convertView;
    }

}
